package com.hugo.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hugo.commonutiles.R;
import com.hugo.eduservice.entity.EduCourse;
import com.hugo.eduservice.entity.EduTeacher;
import com.hugo.eduservice.service.EduCourseService;
import com.hugo.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class indexFrontCourseClontroller {
    //查询前八条热门课程 查询前四条名师
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;

    //查询前八条课程  四个名师
    @GetMapping("index")
    public R index(){
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        //last  拼接sql语句
        wrapper.last("limit 8");
        List<EduCourse> eduList = eduCourseService.list(wrapper);


        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        //last  拼接sql语句
        queryWrapper.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(queryWrapper);
        return R.ok().data("eduList",eduList).data("teacherList",teacherList);
    }


}
